/**
 * ============================================================================
 *
 * Copyright (C) 2012 Android MySportactivities Systems.  All rights reserved. The content 
 * presented herein may not, under any circumstances, be reproduced, in 
 * whole or in any part or form, without written permission from 
 * MySportactivities Systems.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are NOT permitted. Neither the name of MySportactivities Systems,
 * nor the names of contributors may be used to endorse or promote products 
 * derived from this software without specific prior written permission.
 *
 * ============================================================================
 *
 * Author: tuan
 *  
 *
 * Revision History
 * ----------------------------------------------------------------------------
 * Date                Author              Comment, bug number, fix description
 *
 * Feb 29, 2012      tuan@edge-works.net           version 1.0
 *
 * ----------------------------------------------------------------------------
 */
package com.stryker.newproject;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.stryker.R;
import com.stryker.model.Project;

// TODO: Auto-generated Javadoc
/**
 * Created on Feb 29, 2012.
 * 
 * @author tuan
 * @version 1.0
 * @copyright Copyright (c) Android MySportactivities Systems, all rights
 *            reserved
 */

public class ListViewNewProjectsAdapter extends ArrayAdapter<Project> {

	/** The context. */
	Activity context;

	/** The message. */
	Project project;
	// private Dialog progressDialog = null;
	/** The items. */
	private List<Project> items = new ArrayList<Project>();

	/**
	 * Instantiates a new list view private messages adapter.
	 * 
	 * @param context
	 *            the context
	 * @param resource
	 *            the resource
	 * @param items
	 *            the items
	 */
	public ListViewNewProjectsAdapter(Activity context, int resource,
			List<Project> items) {
		super(context, resource, items);
		this.items = items;
		this.context = context;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View row = convertView;
		// Ultilities ultilities=new Ultilities();
		WeatherHolder holder = null;
		project = items.get(position);
		// progressDialog = ultilities.showProgressDialog(context);

		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(R.layout.row_new_project, parent, false);

			holder = new WeatherHolder();
//			holder.progressLoading = (ProgressBar) row
//					.findViewById(R.id.progressLoading);

			holder.avatar = (ImageView) row.findViewById(R.id.iv_avatar);
			holder.txt_full_name = (TextView) row
					.findViewById(R.id.txt_project_name);
			holder.txt_title = (TextView) row.findViewById(R.id.txt_unit);
			holder.txt_date_time = (TextView) row
					.findViewById(R.id.txt_first_date);

			row.setTag(holder);
		} else {
			holder = (WeatherHolder) row.getTag();
		}

		holder.txt_full_name.setText(project.getMprtname());
		holder.txt_title.setText(project.getUnumber());
		holder.txt_date_time.setText(project.getStartdate());

		return row;
	}

	/**
	 * The Class WeatherHolder.
	 */
	static class WeatherHolder {

		/** The avatar. */
		ImageView avatar;

		/** The txt_title. */
		TextView txt_title;

		/** The txt_full_name. */
		TextView txt_full_name;

		/** The txt_date_time. */
		TextView txt_date_time;

		/** The progress loading. */
		ProgressBar progressLoading;
	}

}
